var util= require('util');
var url = require('url');
var express = require('express'); 
var routes = require('./routes');

var server = express.createServer();
//	server.use(express.logger());
	server.use(express.bodyParser());
	server.register('.html', require('ejs'));
	server.set('views', __dirname + '/views');
	server.set('view engine', 'ejs');
server.configure(function(){
	server.use(server.router);
	server.use(express.static(__dirname + '/public'));
	server.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});	

//html
server.get('/', routes.intro);
server.get('/home', routes.home);
server.get('/navigation', routes.navigation);

//ajax
server.get('/electionList', function(req, res) {
	console.log("test");
	var list = new Array();
	list[0] = {regdate:'2012-03-25',electionName:'test',voteID:'1'};
	list[1] = {regdate:'2012-03-25',electionName:'test2',voteID:'2'};
	list[2] = {regdate:'2012-03-25',electionName:'test3',voteID:'3'};
	
	res.write(JSON.stringify(list));
	res.end();
});




server.on('close', function(errno) {
	console.log("server close....");
});
server.get('/404', function(req, res) {
	  res.send('NOT FOUND '+req.url);
	});
console.log("server starting... http://localhost:3000");
server.listen(3000);